package vistas;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.SwingUtilities;

import controller.ControllerPrincipal;

import beans.EntidadBean;
import beans.FacturaBean;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class FacturasGeneradas extends BaseJFrame {
	private JList listaFacturas;
	private JButton jBDetalle;
	private JLabel jLabelTitulo;
	private DefaultListModel listModel = new DefaultListModel();

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				FacturasGeneradas inst = new FacturasGeneradas();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public FacturasGeneradas() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				{
					listaFacturas = new JList(listModel);
					getContentPane().add(listaFacturas);
					// listaFacturas.setBounds(89, 54, 163, 113);
					JScrollPane listScroller = new JScrollPane(listaFacturas);
					listScroller.setBounds(27, 58, 331, 156);
					getContentPane().add(listScroller);
					for (FacturaBean fb : ControllerPrincipal.getInstancia()
							.obtenerFacturas()) {
						listModel.addElement(fb);
					}
				}
				{
					jLabelTitulo = new JLabel();
					getContentPane().add(jLabelTitulo);
					jLabelTitulo.setText("Facturas");
					jLabelTitulo.setBounds(158, 12, 71, 19);
				}
				{
					jBDetalle = new JButton();
					getContentPane().add(jBDetalle);
					jBDetalle.setText("Detalle Facturas");
					jBDetalle.setBounds(139, 233, 106, 22);
					jBDetalle.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent arg0) {
							if (listaFacturas.getSelectedIndex() != -1) {
								FacturaBean fb = (FacturaBean) listaFacturas
										.getSelectedValue();
								DetalleFactura frm = new DetalleFactura(fb);
								frm.setLocationRelativeTo(null);
								frm.setVisible(true);
								_exit();
							}
						}

					});
				}
			}
			{
				this.setSize(387, 306);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void _exit() {
		this.dispose();
	}

}
